//
//  InputViewController.m
//  Manage
//
//  Created by 杨康 on 2017/12/11.
//  Copyright © 2017年 杨康. All rights reserved.
//

#import "InputViewController.h"

@interface InputViewController ()
{
    YKTextField *_inputTF;
}
@end

@implementation InputViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = [NSString stringWithFormat:@"填写%@",self.type];
    
    
    
    
    //账户名
    YKTextField *nameTF=[SingLeton myTextFieldsecure:NO andkeyboardType:UIKeyboardTypeDefault andplaceholder:[NSString stringWithFormat:@"请填写%@",self.type] andLeftImage:nil RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
    }];
    _inputTF=nameTF;
    [self.view addSubview:nameTF];
    [nameTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10+TOP_HEIGHT);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 44));
    }];
    if (self.content) {
        _inputTF.text=self.content;
    }
    
    
    YKButton *saveButton=[SingLeton endButton:[UIColor colorQ] andTitle:@"保存" RequestSuccess:^(UIButton *btn) {
        
        
        NSString *URLString = @"/axq/admin/save";
        /*
         1 uid
         2 loginid  登录手机号(+)
         4 userrole 角色（+)
         5 usertitle 账户名称
         6 contact 联系人
         7 address 地址
         8 telephone 联系电话
         9 headimg 头像url
        
        */
        //字典设值用value 取值用object
        NSMutableDictionary *parameters=[NSMutableDictionary dictionary];
        [parameters setValue:self.uid forKey:@"uid"];
       
        if ([self.type isEqualToString:@"账户名称"]) {
            [parameters setValue:_inputTF.text forKey:@"usertitle"];
        }
        else if ([self.type isEqualToString:@"物业名称"]) {
            [parameters setValue:_inputTF.text forKey:@"usertitle"];
        }
        else if ([self.type isEqualToString:@"联系人"])
        {
          [parameters setValue:_inputTF.text forKey:@"contact"];
        }
        else if ([self.type isEqualToString:@"联系电话"])
        {
          [parameters setValue:_inputTF.text forKey:@"telephone"];
        }
        else if ([self.type isEqualToString:@"地址"])
        {
           [parameters setValue:_inputTF.text forKey:@"address"];
        }
        else if ([self.type isEqualToString:@"民警姓名"])
        {
            [parameters setValue:_inputTF.text forKey:@"usertitle"];
        }
        else if ([self.type isEqualToString:@"电动车厂商"])
        {
            [parameters setValue:_inputTF.text forKey:@"contact"];
        }
        else if ([self.type isEqualToString:@"门店名称"])
        {
            [parameters setValue:_inputTF.text forKey:@"usertitle"];
        }
        
        
        [NetworkPath requestWithMethod:0 andURLString:URLString andParameters:parameters RequestSuccess:^(NSURLResponse *response, id responseObject) {
            NSLog(@"%@",responseObject);
            NSString *code = responseObject[@"code"];
            
            if([code isEqualToString:@"10008"]){
//                NSDictionary *data=responseObject[@"data"];
                [self.navigationController popViewControllerAnimated:YES];
            }
            else
            {
                NSString *str=responseObject[@"msg"];
                
                [self.view makeToast:str];
            }
        } RequestFailed:^(NSError *error) {
            
        }];
    }];
    [self.view addSubview:saveButton];
    [saveButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(nameTF.mas_bottom).mas_offset(20);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-30, 44));
    }];
}



@end
